package com.gitee.neuray.security.modules.param.service.impl;

import com.gitee.neuray.security.common.annotation.DataFilter;
import com.gitee.neuray.security.modules.param.entity.EngineItemEntity;
import com.gitee.neuray.security.modules.sys.shiro.ShiroUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gitee.neuray.security.common.utils.PageUtils;
import com.gitee.neuray.security.common.utils.Query;

import com.gitee.neuray.security.modules.param.dao.ParamItemDao;
import com.gitee.neuray.security.modules.param.entity.ParamItemEntity;
import com.gitee.neuray.security.modules.param.service.ParamItemService;


@Service("paramItemService")
public class ParamItemServiceImpl extends ServiceImpl<ParamItemDao, ParamItemEntity> implements ParamItemService {

    @Autowired
    private ParamItemDao paramItemDao;

    @Override
    @DataFilter(subDept = true, user = false)
    public PageUtils queryPage(Map<String, Object> params) {
        String paramName = (String) params.get("paramName");
        IPage<ParamItemEntity> page = this.page(
                new Query<ParamItemEntity>().getPage(params),
                new QueryWrapper<ParamItemEntity>()
                        .like(StringUtils.isNotBlank(paramName),"param_name", paramName)
                        .eq("dept_id",ShiroUtils.getUserEntity().getDeptId())
        );

        return new PageUtils(page);
    }

    @Override
    public List<ParamItemEntity> getParamByEngine(String engineId, Long deptId) {
        Map<String,Object> map = new HashMap<>();
        map.put("engineId",engineId);
        map.put("deptId",deptId);
        return paramItemDao.getParamByEngine(map);
    }


}
